nsenter: fix FUSE deadlock from synchronous child waits#121
nsenter: fix FUSE deadlock from synchronous child waits#121benjamincburns wants to merge 2 commits into
Conversation
Replace mu.Lock() with mu.TryLock() in the zombie reaper goroutine. Go's sync.RWMutex implements writer-preference: a pending Lock() blocks all subsequent RLock() callers. When the reaper's Lock() is pending while an nsenter child holds RLock, all new FUSE Lookup handlers are blocked from acquiring RLock to start their own nsenter processes. If the nsenter child's operation triggers a FUSE request back to sysbox-fs, the FUSE handler cannot proceed, creating a deadlock. TryLock() does not register a pending writer, so FUSE handlers can still acquire RLock. If TryLock fails, the reaper sleep a second to retry. Fixes: nestybox/sysbox#1002 Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
|
cc @okhowang for visibility |
SendRequest() held the reaper RLock while synchronously waiting for nsenter child processes via Process.Wait(). If a child's exit was delayed by the kernel's fuse_flush on inherited FUSE file descriptors, the RLock was held indefinitely, preventing both the reaper and new FUSE handlers from making progress. Move the pipe read before the PARENT wait (the PARENT writes the pid before exiting) and replace synchronous Process.Wait() calls with background goroutines so the caller releases the RLock promptly. Fixes: nestybox/sysbox#998 Signed-off-by: Ben Burns <803016+benjamincburns@users.noreply.github.com>
09c6630 to
8ddc7c6
Compare
|
I've tested this PR and it fully solves the problem for me as far as I can tell! |
|
Independent confirmation from a separate Sysbox CE 0.7.0 / kernel-6.8 deployment (Coder-style workspaces, inner dockerd + compose stack). Same hang: load into the dozens, idle CPU, procs in What we measured, three ways:
Cycle: This PR fixes it regardless of variant: the real problem is the handler blocking on the child's exit at all. Making the waits async lets the handler answer the request, the client drops Verified: #119+#121 on the 0.7.0 commit, (For transparency, per the note above: also done with Claude Code, arrived at independently.) |
Fixes nestybox/sysbox#998. Builds on #119.
SendRequest()held the reaperRLockwhile synchronously waiting fornsenterchild processes. If a child's exit was delayed byfuse_flushon inherited FUSE file descriptors, theRLockwas held indefinitely, blocking both the reaper and new FUSE handlers.This PR includes the
TryLockfix from #119 and adds:PARENTwait (PARENTwrites pid before exiting)Process.Wait()calls with background goroutinesreapProcessAsyncfor the INIT process to trigger a reaper sweep on exitJust for transparency, I am an experienced software engineer with some systems experience, but I'm not a go dev. I used AI tooling (Claude Code and Claude Opus 4.6) to find the underlying deadlock and author this fix. I'm mentioning that here in case this project has any policies against AI contributions. I don't want to subvert any such policy.
I have tested this fix on my own system. See notes in nestybox/sysbox#998 (comment).